package com.als.healthymananger.controller.impl;

import com.als.healthymananger.controller.ArchivesApi;
import com.als.healthymananger.entity.Archive;
import com.als.healthymananger.service.ArchivesService;
import com.als.healthymananger.utils.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/archives")
public class ArchivesController implements ArchivesApi {

    @Autowired
    private ArchivesService archivesService;

    @Override
    public RespBean createArchives(Archive archive) {
        return archivesService.save(archive)? RespBean.ok("添加成功"): RespBean.badRequest("添加失败");
    }

    @Override
    public RespBean deleteArchives(String archiveId) {
        return archivesService.removeById(archiveId)? RespBean.ok("删除成功"): RespBean.badRequest("删除失败");
    }

    @Override
    public RespBean updateArchives(String archiveId, Archive archive) {
        return archivesService.updateById(archive)? RespBean.ok("修改成功"): RespBean.badRequest("修改失败");
    }

    @Override
    public RespBean getArchives(String archiveId) {
        Archive archive = archivesService.getById(archiveId);
        return archive == null? RespBean.badRequest("获取失败"): RespBean.ok("获取成功");
    }
}
